package com.ruoyi.hl.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hl.reqbean.AddBanZuZhangBean;
import com.ruoyi.hl.reqbean.ShouHuanUserBean;
import com.ruoyi.hl.service.ShouHuanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "手环相关接口")
@RestController
@RequestMapping("/shouhuan")
public class ShouHuanUserController extends BaseController {
    @Autowired
    private ShouHuanService shouHuanService;

    @ApiOperation(value = "添加手环用户") // 接口文档显示内容
    @PostMapping("/addUserInfo")
    @ResponseBody
    public AjaxResult addUserInfo(@Validated @RequestBody ShouHuanUserBean shouHuanUserBean) {
        shouHuanUserBean.setUserID(System.currentTimeMillis() + "");
        int result = shouHuanService.addUserInfo(shouHuanUserBean);
        return AjaxResult.success(result);
    }

    @ApiOperation(value = "修改用户信息") // 接口文档显示内容
    @PostMapping("/updateUserInfo")
    @ResponseBody
    public AjaxResult updateUserInfo(@Validated @RequestBody ShouHuanUserBean shouHuanUserBean) {
        int result = shouHuanService.updateUserInfo(shouHuanUserBean);
        return AjaxResult.success(result);
    }

    @ApiOperation(value = "查询用户列表") // 接口文档显示内容
    @GetMapping("/selectUserList")
    @ResponseBody
    public TableDataInfo selectUserList(ShouHuanUserBean shouHuanUserBean) {
        startPage();
        List<ShouHuanUserBean> list = shouHuanService.selectUserInfo(shouHuanUserBean);
        return getDataTable(list);
    }

    @ApiOperation(value = "批量删除用户") // 接口文档显示内容
    @Log(title = "删除用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds) {
        return toAjax(shouHuanService.deleteUserInfo(userIds));
    }


    /**
     * 班组长 信息增删改查
     */

    @ApiOperation(value = "添加班组长")
    @PostMapping("/addBanZhuInfo")
    @ResponseBody
    public AjaxResult addBanZhuInfo(@Validated @RequestBody AddBanZuZhangBean addBanZuZhangBean) {
        addBanZuZhangBean.setId(System.currentTimeMillis() + "");
        int result = shouHuanService.addBanZuInfo(addBanZuZhangBean);
        return AjaxResult.success(result);
    }

    @ApiOperation(value = "修改班组长信息")
    @PostMapping("/updateBanZhuInfo")
    @ResponseBody
    public AjaxResult updateBanZuInfo(@Validated @RequestBody AddBanZuZhangBean addBanZuZhangBean) {
        int result = shouHuanService.updateBanZuInfo(addBanZuZhangBean);
        return AjaxResult.success(result);
    }

    @ApiOperation(value = "查询班组长列表")
    @PostMapping("/selectBanZhuList")
    @ResponseBody
    public TableDataInfo selectBanZhuList(AddBanZuZhangBean addBanZuZhangBean) {
        startPage();
        List<AddBanZuZhangBean> list = shouHuanService.selectBanZuInfo(addBanZuZhangBean);
        return getDataTable(list);
    }

    @ApiOperation(value = "根据ID删除班组长")
    @GetMapping("/deleteBanZU")
    @ResponseBody
    public AjaxResult removeBanZhu(String id) {
        return toAjax(shouHuanService.deleteBanZuInfo(id));
    }


    @ApiOperation(value = "查询班组长详情")
    @GetMapping("/selectBanZhuDetail")
    @ResponseBody
    public AjaxResult selectBanZuDetail(String id) {
        AddBanZuZhangBean data = shouHuanService.selectBanZuDetail(id);
        return AjaxResult.success(data);
    }

}
